import { FactoryTaskHelper } from "GameLoop/WorldState/EntityManager/Entitys/room/factory/FactoryTaskHelper";
import { State } from "framework/FSM/AState";
 
export class  FactoryPutResource<T extends IStateArg<Room>> extends State<T>
{

    public getActions(arg:T):Action[]
    {
        const actions:Action[] = [];
        const task = arg.entity.getTaskByType("factory")[0] ;
 
        const toptask = FactoryTaskHelper.Top(task.data.arg);
        const coreEntity = arg.entity.getEntity("CoreEntity");
        const factory = coreEntity.Factory;
        if(toptask && factory)
        {
            const child = COMMODITIES[ toptask.target].components;
            for(let key in factory.store)
            {
                if(!child[key as  CommodityConstant])
                {
                    const code =  coreEntity.transferOutTask(factory,{resourceType:key as ResourceConstant,amount:factory.store.getUsedCapacity(key as ResourceConstant)});
                    if(code)
                    {
                        task.data.arg.transportKey = code;
                    }
                    break;
                }
            }
        }
        return actions;
    }
}
